package com.hm.service.api.wx;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.hm.service.framework.PostController;
import com.hm.service.service.main.TaskHandleService;
import com.hm.service.service.wx.WeChatPublicService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.URLEncoder;
import java.util.HashMap;


@RestController
@RequestMapping(value = "/WX", produces = {"application/json;charset=UTF-8"})
public class SZCG_003_000_000 extends PostController {

    private final WeChatPublicService weChatPublicService;


    public SZCG_003_000_000(WeChatPublicService weChatPublicService) {
        this.weChatPublicService = weChatPublicService;
    }

    //微信网页授权-用code换取openID->作用域为snsapi_base
    @PostMapping(value = "/003_000_000")
    public String doPost(HttpServletRequest request) {
        return handleRequest(request);
    }

    @Override
    protected String postRequest(HashMap<String, String> param) {
        //解析json
        String requestBody = param.get("requestBody");
        JSONObject jsonObject = (JSONObject) JSON.parse(requestBody);
        String code = jsonObject.getString("code");
        return weChatPublicService.getOpenid(code);
    }
}
